home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / braillegenerator.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  45.9 KB  |  1,452 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Utilities for obtaining braille strings for objects.  In general,
  5. there probably should be a singleton instance of the BrailleGenerator
  6. class.  For those wishing to override the braille generators, however,
  7. one can create a new instance and replace/extend the braille
  8. generators as they see fit.'''
  9. __id__ = '$Id: braillegenerator.py 4446 2009-01-21 19:54:21Z wwalker $'
  10. __version__ = '$Revision: 4446 $'
  11. __date__ = '$Date: 2009-01-21 14:54:21 -0500 (Wed, 21 Jan 2009) $'
  12. __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
  13. __license__ = 'LGPL'
  14. import pyatspi
  15. import braille
  16. import debug
  17. import orca_state
  18. import rolenames
  19. import settings
  20. from orca_i18n import _
  21. from orca_i18n import ngettext
  22.  
  23. class BrailleGenerator:
  24.     '''Takes accessible objects and produces a list of braille Regions
  25.     for those objects.  See the getBrailleRegions method, which is the
  26.     primary entry point.  Subclasses can feel free to override/extend
  27.     the brailleGenerators instance field as they see fit.'''
  28.     SKIP_CONTEXT_ROLES = (pyatspi.ROLE_MENU, pyatspi.ROLE_MENU_BAR, pyatspi.ROLE_PAGE_TAB_LIST, pyatspi.ROLE_COMBO_BOX)
  29.     
  30.     def __init__(self, script):
  31.         self._script = script
  32.         self.brailleGenerators = { }
  33.         self.brailleGenerators[pyatspi.ROLE_ALERT] = self._getBrailleRegionsForAlert
  34.         self.brailleGenerators[pyatspi.ROLE_ANIMATION] = self._getBrailleRegionsForAnimation
  35.         self.brailleGenerators[pyatspi.ROLE_ARROW] = self._getBrailleRegionsForArrow
  36.         self.brailleGenerators[pyatspi.ROLE_CHECK_BOX] = self._getBrailleRegionsForCheckBox
  37.         self.brailleGenerators[pyatspi.ROLE_CHECK_MENU_ITEM] = self._getBrailleRegionsForCheckMenuItem
  38.         self.brailleGenerators[pyatspi.ROLE_COLUMN_HEADER] = self._getBrailleRegionsForColumnHeader
  39.         self.brailleGenerators[pyatspi.ROLE_COMBO_BOX] = self._getBrailleRegionsForComboBox
  40.         self.brailleGenerators[pyatspi.ROLE_DESKTOP_ICON] = self._getBrailleRegionsForDesktopIcon
  41.         self.brailleGenerators[pyatspi.ROLE_DIAL] = self._getBrailleRegionsForDial
  42.         self.brailleGenerators[pyatspi.ROLE_DIALOG] = self._getBrailleRegionsForDialog
  43.         self.brailleGenerators[pyatspi.ROLE_DIRECTORY_PANE] = self._getBrailleRegionsForDirectoryPane
  44.         self.brailleGenerators[pyatspi.ROLE_EMBEDDED] = self._getBrailleRegionsForEmbedded
  45.         self.brailleGenerators[pyatspi.ROLE_FRAME] = self._getBrailleRegionsForFrame
  46.         self.brailleGenerators[pyatspi.ROLE_HTML_CONTAINER] = self._getBrailleRegionsForHtmlContainer
  47.         self.brailleGenerators[pyatspi.ROLE_ICON] = self._getBrailleRegionsForIcon
  48.         self.brailleGenerators[pyatspi.ROLE_IMAGE] = self._getBrailleRegionsForImage
  49.         self.brailleGenerators[pyatspi.ROLE_LABEL] = self._getBrailleRegionsForLabel
  50.         self.brailleGenerators[pyatspi.ROLE_LIST] = self._getBrailleRegionsForList
  51.         self.brailleGenerators[pyatspi.ROLE_MENU] = self._getBrailleRegionsForMenu
  52.         self.brailleGenerators[pyatspi.ROLE_MENU_BAR] = self._getBrailleRegionsForMenuBar
  53.         self.brailleGenerators[pyatspi.ROLE_MENU_ITEM] = self._getBrailleRegionsForMenuItem
  54.         self.brailleGenerators[pyatspi.ROLE_OPTION_PANE] = self._getBrailleRegionsForOptionPane
  55.         self.brailleGenerators[pyatspi.ROLE_PAGE_TAB] = self._getBrailleRegionsForPageTab
  56.         self.brailleGenerators[pyatspi.ROLE_PAGE_TAB_LIST] = self._getBrailleRegionsForPageTabList
  57.         self.brailleGenerators[pyatspi.ROLE_PANEL] = self._getBrailleRegionsForPanel
  58.         self.brailleGenerators[pyatspi.ROLE_PARAGRAPH] = self._getBrailleRegionsForText
  59.         self.brailleGenerators[pyatspi.ROLE_PASSWORD_TEXT] = self._getBrailleRegionsForText
  60.         self.brailleGenerators[pyatspi.ROLE_PROGRESS_BAR] = self._getBrailleRegionsForProgressBar
  61.         self.brailleGenerators[pyatspi.ROLE_PUSH_BUTTON] = self._getBrailleRegionsForPushButton
  62.         self.brailleGenerators[pyatspi.ROLE_RADIO_BUTTON] = self._getBrailleRegionsForRadioButton
  63.         self.brailleGenerators[pyatspi.ROLE_RADIO_MENU_ITEM] = self._getBrailleRegionsForRadioMenuItem
  64.         self.brailleGenerators[pyatspi.ROLE_ROW_HEADER] = self._getBrailleRegionsForRowHeader
  65.         self.brailleGenerators[pyatspi.ROLE_SCROLL_BAR] = self._getBrailleRegionsForScrollBar
  66.         self.brailleGenerators[pyatspi.ROLE_SCROLL_PANE] = self._getBrailleRegionsForScrollPane
  67.         self.brailleGenerators[pyatspi.ROLE_SLIDER] = self._getBrailleRegionsForSlider
  68.         self.brailleGenerators[pyatspi.ROLE_SPIN_BUTTON] = self._getBrailleRegionsForSpinButton
  69.         self.brailleGenerators[pyatspi.ROLE_SPLIT_PANE] = self._getBrailleRegionsForSplitPane
  70.         self.brailleGenerators[pyatspi.ROLE_TABLE] = self._getBrailleRegionsForTable
  71.         self.brailleGenerators[pyatspi.ROLE_TABLE_CELL] = self._getBrailleRegionsForTableCellRow
  72.         self.brailleGenerators[pyatspi.ROLE_TABLE_COLUMN_HEADER] = self._getBrailleRegionsForTableColumnHeader
  73.         self.brailleGenerators[pyatspi.ROLE_TABLE_ROW_HEADER] = self._getBrailleRegionsForTableRowHeader
  74.         self.brailleGenerators[pyatspi.ROLE_TEAROFF_MENU_ITEM] = self._getBrailleRegionsForMenu
  75.         self.brailleGenerators[pyatspi.ROLE_TERMINAL] = self._getBrailleRegionsForTerminal
  76.         self.brailleGenerators[pyatspi.ROLE_TEXT] = self._getBrailleRegionsForText
  77.         self.brailleGenerators[pyatspi.ROLE_TOGGLE_BUTTON] = self._getBrailleRegionsForToggleButton
  78.         self.brailleGenerators[pyatspi.ROLE_TOOL_BAR] = self._getBrailleRegionsForToolBar
  79.         self.brailleGenerators[pyatspi.ROLE_TREE] = self._getBrailleRegionsForTable
  80.         self.brailleGenerators[pyatspi.ROLE_TREE_TABLE] = self._getBrailleRegionsForTable
  81.         self.brailleGenerators[pyatspi.ROLE_WINDOW] = self._getBrailleRegionsForWindow
  82.  
  83.     
  84.     def _getTextForAccelerator(self, obj):
  85.         '''Returns a string to be displayed that describes the keyboard
  86.         accelerator (and possibly shortcut) for the given object.
  87.  
  88.         Arguments:
  89.         - obj: the Accessible object
  90.  
  91.         Returns a string to be displayed.
  92.         '''
  93.         if settings.brailleVerbosityLevel == settings.VERBOSITY_LEVEL_VERBOSE:
  94.             text = ''
  95.             result = self._script.getKeyBinding(obj)
  96.             accelerator = result[2]
  97.             if len(accelerator) > 0:
  98.                 text += '(' + accelerator + ')'
  99.             
  100.             return text
  101.         return None
  102.  
  103.     
  104.     def _getTextForAvailability(self, obj):
  105.         '''Returns a string to be displayed that describes the availability
  106.         of the given object.
  107.  
  108.         Arguments:
  109.         - obj: the Accessible object
  110.  
  111.         Returns a string to be displayed.
  112.         '''
  113.         state = obj.getState()
  114.         if not state.contains(pyatspi.STATE_SENSITIVE):
  115.             return _('grayed')
  116.         return None
  117.  
  118.     
  119.     def _getTextForRequiredObject(self, obj):
  120.         '''Returns a string to be displayed that describes the required
  121.         state of the given object.
  122.  
  123.         Arguments:
  124.         - obj: the Accessible object
  125.  
  126.         Returns a string to be displayed.
  127.         '''
  128.         if not settings.presentRequiredState:
  129.             return None
  130.         state = obj.getState()
  131.         if state.contains(pyatspi.STATE_REQUIRED):
  132.             return settings.brailleRequiredStateString
  133.         return None
  134.  
  135.     
  136.     def _getTextForRole(self, obj, role = None):
  137.         if settings.brailleVerbosityLevel == settings.VERBOSITY_LEVEL_VERBOSE and obj.getRole() != pyatspi.ROLE_UNKNOWN:
  138.             return rolenames.getBrailleForRoleName(obj, role)
  139.         return None
  140.  
  141.     
  142.     def _debugGenerator(self, generatorName, obj):
  143.         '''Prints debug.LEVEL_FINER information regarding the braille
  144.         generator.
  145.  
  146.         Arguments:
  147.         - generatorName: the name of the generator
  148.         - obj: the object being presented
  149.         '''
  150.         debug.println(debug.LEVEL_FINER, 'GENERATOR: %s' % generatorName)
  151.         debug.println(debug.LEVEL_FINER, '           obj             = %s' % obj.name)
  152.         debug.println(debug.LEVEL_FINER, '           role            = %s' % obj.getRoleName())
  153.  
  154.     
  155.     def _getDefaultBrailleRegions(self, obj, role = None):
  156.         """Gets text to be displayed for the current object's name,
  157.         role, and any accelerators.  This is usually the fallback
  158.         braille generator should no other specialized braille
  159.         generator exist for this object.
  160.  
  161.         Arguments:
  162.         - obj: an Accessible
  163.         - role: Role to use as an override.
  164.  
  165.         Returns a list where the first element is a list of Regions to
  166.         display and the second element is the Region which should get
  167.         focus.
  168.         """
  169.         self._debugGenerator('_getDefaultBrailleRegions', obj)
  170.         regions = []
  171.         text = ''
  172.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  173.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  174.         text = self._script.appendString(text, self._script.getTextForValue(obj))
  175.         text = self._script.appendString(text, self._getTextForRole(obj, role))
  176.         text = self._script.appendString(text, self._getTextForRequiredObject(obj))
  177.         regions = []
  178.         componentRegion = braille.Component(obj, text)
  179.         regions.append(componentRegion)
  180.         return [
  181.             regions,
  182.             componentRegion]
  183.  
  184.     
  185.     def _getBrailleRegionsForAlert(self, obj):
  186.         '''Gets the title of the dialog and the contents of labels inside the
  187.         dialog that are not associated with any other objects.
  188.  
  189.         Arguments:
  190.         - obj: the Accessible dialog
  191.  
  192.         Returns a list where the first element is a list of Regions to display
  193.         and the second element is the Region which should get focus.
  194.         '''
  195.         self._debugGenerator('_getBrailleRegionsForAlert', obj)
  196.         return self._getDefaultBrailleRegions(obj)
  197.  
  198.     
  199.     def _getBrailleRegionsForAnimation(self, obj):
  200.         '''Gets the title of the dialog and the contents of labels inside the
  201.         dialog that are not associated with any other objects.
  202.  
  203.         Arguments:
  204.         - obj: the Accessible dialog
  205.  
  206.         Returns a list where the first element is a list of Regions to display
  207.         and the second element is the Region which should get focus.
  208.         '''
  209.         self._debugGenerator('_getBrailleRegionsForAnimation', obj)
  210.         text = ''
  211.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  212.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  213.         text = self._script.appendString(text, self._getTextForRole(obj))
  214.         text = self._script.appendString(text, obj.description, ': ')
  215.         regions = []
  216.         componentRegion = braille.Component(obj, text)
  217.         regions.append(componentRegion)
  218.         return [
  219.             regions,
  220.             componentRegion]
  221.  
  222.     
  223.     def _getBrailleRegionsForArrow(self, obj):
  224.         '''Gets text to be displayed for an arrow.
  225.  
  226.         Arguments:
  227.         - obj: the arrow
  228.  
  229.         Returns a list where the first element is a list of Regions to display
  230.         and the second element is the Region which should get focus.
  231.         '''
  232.         self._debugGenerator('_getBrailleRegionsForArrow', obj)
  233.         return self._getDefaultBrailleRegions(obj)
  234.  
  235.     
  236.     def _getBrailleRegionsForCheckBox(self, obj):
  237.         '''Get the braille for a check box.  If the check box already had
  238.         focus, then only the state is displayed.
  239.  
  240.         Arguments:
  241.         - obj: the check box
  242.  
  243.         Returns a list where the first element is a list of Regions to display
  244.         and the second element is the Region which should get focus.
  245.         '''
  246.         self._debugGenerator('_getBrailleRegionsForCheckBox', obj)
  247.         state = obj.getState()
  248.         if state.contains(pyatspi.STATE_INDETERMINATE):
  249.             indicatorindex = 2
  250.         elif state.contains(pyatspi.STATE_CHECKED):
  251.             indicatorindex = 1
  252.         else:
  253.             indicatorindex = 0
  254.         text = ''
  255.         state = obj.getState()
  256.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  257.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  258.         text = self._script.appendString(text, self._getTextForRole(obj, pyatspi.ROLE_CHECK_BOX))
  259.         text = self._script.appendString(text, self._getTextForRequiredObject(obj))
  260.         regions = []
  261.         componentRegion = braille.Component(obj, text, indicator = settings.brailleCheckBoxIndicators[indicatorindex])
  262.         regions.append(componentRegion)
  263.         return [
  264.             regions,
  265.             componentRegion]
  266.  
  267.     
  268.     def _getBrailleRegionsForCheckMenuItem(self, obj):
  269.         '''Get the braille for a check menu item.  If the check menu item
  270.         already had focus, then only the state is displayed.
  271.  
  272.         Arguments:
  273.         - obj: the check menu item
  274.  
  275.         Returns a list where the first element is a list of Regions to display
  276.         and the second element is the Region which should get focus.
  277.         '''
  278.         self._debugGenerator('_getBrailleRegionsForCheckMenuItem', obj)
  279.         state = obj.getState()
  280.         if state.contains(pyatspi.STATE_INDETERMINATE):
  281.             indicatorindex = 2
  282.         elif state.contains(pyatspi.STATE_CHECKED):
  283.             indicatorindex = 1
  284.         else:
  285.             indicatorindex = 0
  286.         text = ''
  287.         state = obj.getState()
  288.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  289.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  290.         if obj == orca_state.locusOfFocus:
  291.             text = self._script.appendString(text, self._getTextForRole(obj))
  292.             text = self._script.appendString(text, self._getTextForAvailability(obj))
  293.             text = self._script.appendString(text, self._getTextForAccelerator(obj), '')
  294.         
  295.         regions = []
  296.         componentRegion = braille.Component(obj, text, indicator = settings.brailleCheckBoxIndicators[indicatorindex])
  297.         regions.append(componentRegion)
  298.         return [
  299.             regions,
  300.             componentRegion]
  301.  
  302.     
  303.     def _getBrailleRegionsForColumnHeader(self, obj):
  304.         '''Get the braille for a column header.
  305.  
  306.         Arguments:
  307.         - obj: the column header
  308.  
  309.         Returns a list where the first element is a list of Regions to display
  310.         and the second element is the Region which should get focus.
  311.         '''
  312.         self._debugGenerator('_getBrailleRegionsForColumnHeader', obj)
  313.         return self._getDefaultBrailleRegions(obj)
  314.  
  315.     
  316.     def _getBrailleRegionsForComboBox(self, obj):
  317.         '''Get the braille for a combo box.  If the combo box already has
  318.         focus, then only the selection is displayed.
  319.  
  320.         Arguments:
  321.         - obj: the combo box
  322.  
  323.         Returns a list where the first element is a list of Regions to display
  324.         and the second element is the Region which should get focus.
  325.         '''
  326.         self._debugGenerator('_getBrailleRegionsForComboBox', obj)
  327.         regions = []
  328.         focusedRegionIndex = 0
  329.         label = self._script.getDisplayedLabel(obj)
  330.         if label and len(label) > 0:
  331.             regions.append(braille.Region(label + ' '))
  332.             focusedRegionIndex = 1
  333.         
  334.         textObj = None
  335.         for child in obj:
  336.             if child and child.getRole() == pyatspi.ROLE_TEXT:
  337.                 textObj = child
  338.                 continue
  339.         
  340.         if textObj and textObj.getState().contains(pyatspi.STATE_EDITABLE):
  341.             textRegion = braille.Text(textObj)
  342.             regions.append(textRegion)
  343.         else:
  344.             displayedText = self._script.getDisplayedText(obj)
  345.             if displayedText:
  346.                 regions.append(braille.Region(displayedText))
  347.             
  348.         regions.append(braille.Region(' ' + rolenames.getBrailleForRoleName(obj)))
  349.         if focusedRegionIndex >= len(regions):
  350.             focusedRegionIndex = 0
  351.         
  352.         if len(regions) == 0:
  353.             focusedRegion = None
  354.         else:
  355.             focusedRegion = regions[focusedRegionIndex]
  356.         return [
  357.             regions,
  358.             focusedRegion]
  359.  
  360.     
  361.     def _getBrailleRegionsForDesktopIcon(self, obj):
  362.         '''Get the braille for a desktop icon.
  363.  
  364.         Arguments:
  365.         - obj: the desktop icon
  366.  
  367.         Returns a list where the first element is a list of Regions to display
  368.         and the second element is the Region which should get focus.
  369.         '''
  370.         self._debugGenerator('_getBrailleRegionsForDesktopIcon', obj)
  371.         return self._getDefaultBrailleRegions(obj)
  372.  
  373.     
  374.     def _getBrailleRegionsForDial(self, obj):
  375.         '''Get the braille for a dial.
  376.  
  377.         Arguments:
  378.         - obj: the dial
  379.  
  380.         Returns a list where the first element is a list of Regions to display
  381.         and the second element is the Region which should get focus.
  382.         '''
  383.         self._debugGenerator('_getBrailleRegionsForDial', obj)
  384.         return self._getDefaultBrailleRegions(obj)
  385.  
  386.     
  387.     def _getBrailleRegionsForDialog(self, obj):
  388.         '''Get the braille for a dialog box.
  389.  
  390.         Arguments:
  391.         - obj: the dialog box
  392.  
  393.         Returns a list where the first element is a list of Regions to display
  394.         and the second element is the Region which should get focus.
  395.         '''
  396.         self._debugGenerator('_getBrailleRegionsForDialog', obj)
  397.         return self._getBrailleRegionsForAlert(obj)
  398.  
  399.     
  400.     def _getBrailleRegionsForDirectoryPane(self, obj):
  401.         '''Get the braille for a directory pane.
  402.  
  403.         Arguments:
  404.         - obj: the dial
  405.  
  406.         Returns a list where the first element is a list of Regions to display
  407.         and the second element is the Region which should get focus.
  408.         '''
  409.         self._debugGenerator('_getBrailleRegionsForDirectoryPane', obj)
  410.         return self._getDefaultBrailleRegions(obj)
  411.  
  412.     
  413.     def _getBrailleRegionsForEmbedded(self, obj, role = None):
  414.         '''Gets text to be displayed for the current embedded object.
  415.  
  416.         Arguments:
  417.         - obj: an Accessible
  418.         - role: Role to use as an override.
  419.  
  420.         Returns a list where the first element is a list of Regions to
  421.         display and the second element is the Region which should get
  422.         focus.
  423.         '''
  424.         self._debugGenerator('_getBrailleRegionsForEmbedded', obj)
  425.         regions = []
  426.         text = ''
  427.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  428.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  429.         if not text:
  430.             
  431.             try:
  432.                 text = obj.getApplication().name
  433.  
  434.         
  435.         regions = []
  436.         componentRegion = braille.Component(obj, text)
  437.         regions.append(componentRegion)
  438.         return [
  439.             regions,
  440.             componentRegion]
  441.  
  442.     
  443.     def _getBrailleRegionsForFrame(self, obj):
  444.         '''Get the braille for a frame.
  445.  
  446.         Arguments:
  447.         - obj: the frame
  448.  
  449.         Returns a list where the first element is a list of Regions to display
  450.         and the second element is the Region which should get focus.
  451.         '''
  452.         self._debugGenerator('_getBrailleRegionsForFrame', obj)
  453.         regions = []
  454.         text = ''
  455.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  456.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  457.         text = self._script.appendString(text, self._script.getTextForValue(obj))
  458.         text = self._script.appendString(text, self._getTextForRole(obj))
  459.         alertAndDialogCount = self._script.getUnfocusedAlertAndDialogCount(obj)
  460.         if alertAndDialogCount > 0:
  461.             line = ngettext('(%d dialog)', '(%d dialogs)', alertAndDialogCount) % alertAndDialogCount
  462.             text = self._script.appendString(text, line)
  463.         
  464.         regions = []
  465.         componentRegion = braille.Component(obj, text)
  466.         regions.append(componentRegion)
  467.         return [
  468.             regions,
  469.             componentRegion]
  470.  
  471.     
  472.     def _getBrailleRegionsForHtmlContainer(self, obj):
  473.         '''Get the braille for an HTML container.
  474.  
  475.         Arguments:
  476.         - obj: the dial
  477.  
  478.         Returns a list where the first element is a list of Regions to display
  479.         and the second element is the Region which should get focus.
  480.         '''
  481.         self._debugGenerator('_getBrailleRegionsForHtmlContainer', obj)
  482.         return self._getDefaultBrailleRegions(obj)
  483.  
  484.     
  485.     def _getBrailleRegionsForIcon(self, obj):
  486.         '''Get the braille for an icon.
  487.  
  488.         Arguments:
  489.         - obj: the icon
  490.  
  491.         Returns a list where the first element is a list of Regions to display
  492.         and the second element is the Region which should get focus.
  493.         '''
  494.         self._debugGenerator('_getBrailleRegionsForIcon', obj)
  495.         text = ''
  496.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  497.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  498.         
  499.         try:
  500.             image = obj.queryImage()
  501.         except NotImplementedError:
  502.             pass
  503.  
  504.         description = image.imageDescription
  505.         if len(description):
  506.             text = self._script.appendString(text, description)
  507.         
  508.         text = self._script.appendString(text, self._getTextForRole(obj))
  509.         regions = []
  510.         componentRegion = braille.Component(obj, text)
  511.         regions.append(componentRegion)
  512.         return [
  513.             regions,
  514.             componentRegion]
  515.  
  516.     
  517.     def _getBrailleRegionsForImage(self, obj):
  518.         '''Get the braille for an image.
  519.  
  520.         Arguments:
  521.         - obj: the image
  522.  
  523.         Returns a list where the first element is a list of Regions to display
  524.         and the second element is the Region which should get focus.
  525.         '''
  526.         self._debugGenerator('_getBrailleRegionsForImage', obj)
  527.         return self._getDefaultBrailleRegions(obj, pyatspi.ROLE_IMAGE)
  528.  
  529.     
  530.     def _getBrailleRegionsForLabel(self, obj):
  531.         '''Get the braille for a label.
  532.  
  533.         Arguments:
  534.         - obj: the label
  535.  
  536.         Returns a list where the first element is a list of Regions to display
  537.         and the second element is the Region which should get focus.
  538.         '''
  539.         self._debugGenerator('_getBrailleRegionsForLabel', obj)
  540.         regions = []
  541.         textRegion = braille.Text(obj, self._script.getDisplayedLabel(obj), settings.brailleEOLIndicator)
  542.         regions.append(textRegion)
  543.         return [
  544.             regions,
  545.             textRegion]
  546.  
  547.     
  548.     def _getBrailleRegionsForList(self, obj):
  549.         '''Get the braille for a list.
  550.  
  551.         Arguments:
  552.         - obj: the list
  553.  
  554.         Returns a list where the first element is a list of Regions to display
  555.         and the second element is the Region which should get focus.
  556.         '''
  557.         self._debugGenerator('_getBrailleRegionsForList', obj)
  558.         return self._getDefaultBrailleRegions(obj)
  559.  
  560.     
  561.     def _getBrailleRegionsForListItem(self, obj):
  562.         '''Get the braille for a listitem.
  563.  
  564.         Arguments:
  565.         - obj: the listitem
  566.  
  567.         '''
  568.         self._debugGenerator('_getBrailleRegionsForListItem', obj)
  569.         text = ''
  570.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  571.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  572.         state = obj.getState()
  573.         if state.contains(pyatspi.STATE_EXPANDABLE):
  574.             if state.contains(pyatspi.STATE_EXPANDED):
  575.                 text = self._script.appendString(text, _('expanded'))
  576.             else:
  577.                 text = self._script.appendString(text, _('collapsed'))
  578.         
  579.         if obj == orca_state.locusOfFocus:
  580.             text = self._script.appendString(text, self._getTextForRole(obj))
  581.             text = self._script.appendString(text, self._getTextForAvailability(obj))
  582.             text = self._script.appendString(text, self._getTextForAccelerator(obj), '')
  583.         
  584.         level = self._script.getNodeLevel(obj)
  585.         if level >= 0:
  586.             text = self._script.appendString(text, _('LEVEL %d') % (level + 1))
  587.         
  588.         regions = []
  589.         componentRegion = braille.Component(obj, text)
  590.         regions.append(componentRegion)
  591.         return [
  592.             regions,
  593.             componentRegion]
  594.  
  595.     
  596.     def _getBrailleRegionsForMenu(self, obj):
  597.         '''Get the braille for a menu.
  598.  
  599.         Arguments:
  600.         - obj: the menu
  601.  
  602.         Returns a list where the first element is a list of Regions to display
  603.         and the second element is the Region which should get focus.
  604.         '''
  605.         self._debugGenerator('_getBrailleRegionsForMenu', obj)
  606.         text = ''
  607.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  608.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  609.         text = self._script.appendString(text, rolenames.getBrailleForRoleName(obj))
  610.         if obj == orca_state.locusOfFocus:
  611.             text = self._script.appendString(text, self._getTextForAvailability(obj))
  612.             text = self._script.appendString(text, self._getTextForAccelerator(obj), '')
  613.         
  614.         regions = []
  615.         componentRegion = braille.Component(obj, text)
  616.         regions.append(componentRegion)
  617.         return [
  618.             regions,
  619.             componentRegion]
  620.  
  621.     
  622.     def _getBrailleRegionsForMenuBar(self, obj):
  623.         '''Get the braille for a menu bar.
  624.  
  625.         Arguments:
  626.         - obj: the menu bar
  627.  
  628.         Returns a list where the first element is a list of Regions to display
  629.         and the second element is the Region which should get focus.
  630.         '''
  631.         self._debugGenerator('_getBrailleRegionsForMenuBar', obj)
  632.         return self._getDefaultBrailleRegions(obj)
  633.  
  634.     
  635.     def _getBrailleRegionsForMenuItem(self, obj):
  636.         '''Get the braille for a menu item.
  637.  
  638.         Arguments:
  639.         - obj: the menu item
  640.  
  641.         Returns a list where the first element is a list of Regions to display
  642.         and the second element is the Region which should get focus.
  643.         '''
  644.         self._debugGenerator('_getBrailleRegionsForMenuItem', obj)
  645.         text = ''
  646.         state = obj.getState()
  647.         if state.contains(pyatspi.STATE_CHECKED):
  648.             indicator = settings.brailleCheckBoxIndicators[1]
  649.         else:
  650.             indicator = ''
  651.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  652.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  653.         if obj == orca_state.locusOfFocus:
  654.             text = self._script.appendString(text, self._getTextForAvailability(obj))
  655.             text = self._script.appendString(text, self._getTextForAccelerator(obj), '')
  656.         
  657.         regions = []
  658.         componentRegion = braille.Component(obj, text, indicator = indicator)
  659.         regions.append(componentRegion)
  660.         return [
  661.             regions,
  662.             componentRegion]
  663.  
  664.     
  665.     def _getBrailleRegionsForText(self, obj):
  666.         '''Get the braille for a text component.
  667.  
  668.         Arguments:
  669.         - obj: the text component
  670.  
  671.         Returns a list where the first element is a list of Regions to display
  672.         and the second element is the Region which should get focus.
  673.         '''
  674.         self._debugGenerator('_getBrailleRegionsForText', obj)
  675.         regions = []
  676.         textRegion = braille.Text(obj, self._script.getDisplayedLabel(obj), settings.brailleEOLIndicator)
  677.         regions.append(textRegion)
  678.         text = self._getTextForRequiredObject(obj)
  679.         if text:
  680.             regions.append(braille.Region(' ' + text))
  681.         
  682.         if settings.presentReadOnlyText and self._script.isReadOnlyTextArea(obj):
  683.             regions.append(braille.Region(' ' + settings.brailleReadOnlyString))
  684.         
  685.         return [
  686.             regions,
  687.             textRegion]
  688.  
  689.     
  690.     def _getBrailleRegionsForOptionPane(self, obj):
  691.         '''Get the braille for an option pane.
  692.  
  693.         Arguments:
  694.         - obj: the option pane
  695.  
  696.         Returns a list where the first element is a list of Regions to display
  697.         and the second element is the Region which should get focus.
  698.         '''
  699.         self._debugGenerator('_getBrailleRegionsForOptionPane', obj)
  700.         return self._getDefaultBrailleRegions(obj)
  701.  
  702.     
  703.     def _getBrailleRegionsForPageTab(self, obj):
  704.         '''Get the braille for a page tab.
  705.  
  706.         Arguments:
  707.         - obj: the page tab
  708.  
  709.         Returns a list where the first element is a list of Regions to display
  710.         and the second element is the Region which should get focus.
  711.         '''
  712.         self._debugGenerator('_getBrailleRegionsForPageTab', obj)
  713.         text = ''
  714.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  715.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  716.         text = self._script.appendString(text, self._getTextForRole(obj))
  717.         if obj == orca_state.locusOfFocus:
  718.             text = self._script.appendString(text, self._getTextForAvailability(obj))
  719.             text = self._script.appendString(text, self._getTextForAccelerator(obj), '')
  720.         
  721.         regions = []
  722.         componentRegion = braille.Component(obj, text)
  723.         regions.append(componentRegion)
  724.         return [
  725.             regions,
  726.             componentRegion]
  727.  
  728.     
  729.     def _getBrailleRegionsForPageTabList(self, obj):
  730.         '''Get the braille for a page tab list.
  731.  
  732.         Arguments:
  733.         - obj: the page tab list
  734.  
  735.         Returns a list where the first element is a list of Regions to display
  736.         and the second element is the Region which should get focus.
  737.         '''
  738.         self._debugGenerator('_getBrailleRegionsForPageTabList', obj)
  739.         return self._getDefaultBrailleRegions(obj)
  740.  
  741.     
  742.     def _getBrailleRegionsForPanel(self, obj):
  743.         '''Gets text to be displayed for a panel.
  744.  
  745.         Arguments:
  746.         - obj: an Accessible
  747.  
  748.         Returns a list where the first element is a list of Regions to
  749.         display and the second element is the Region which should get
  750.         focus.
  751.         '''
  752.         self._debugGenerator('_getBrailleRegionsForPanel', obj)
  753.         regions = []
  754.         text = ''
  755.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  756.         if len(text) == 0:
  757.             text = self._script.appendString(text, self._script.getDisplayedText(obj))
  758.         
  759.         text = self._script.appendString(text, self._getTextForRole(obj))
  760.         regions = []
  761.         componentRegion = braille.Component(obj, text)
  762.         regions.append(componentRegion)
  763.         return [
  764.             regions,
  765.             componentRegion]
  766.  
  767.     
  768.     def _getBrailleRegionsForProgressBar(self, obj):
  769.         '''Get the braille for a progress bar.  If the object already
  770.         had focus, just the new value is displayed.
  771.  
  772.         Arguments:
  773.         - obj: the progress bar
  774.  
  775.         Returns a list where the first element is a list of Regions to display
  776.         and the second element is the Region which should get focus.
  777.         '''
  778.         self._debugGenerator('_getBrailleRegionsForProgressBar', obj)
  779.         return self._getDefaultBrailleRegions(obj)
  780.  
  781.     
  782.     def _getBrailleRegionsForPushButton(self, obj):
  783.         '''Get the braille for a push button
  784.  
  785.         Arguments:
  786.         - obj: the push button
  787.  
  788.         Returns a list where the first element is a list of Regions to display
  789.         and the second element is the Region which should get focus.
  790.         '''
  791.         self._debugGenerator('_getBrailleRegionsForPushButton', obj)
  792.         regions = []
  793.         text = ''
  794.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  795.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  796.         if not text and obj.description:
  797.             text = self._script.appendString(text, obj.description)
  798.         
  799.         text = self._script.appendString(text, self._getTextForRole(obj))
  800.         regions = []
  801.         componentRegion = braille.Component(obj, text)
  802.         regions.append(componentRegion)
  803.         return [
  804.             regions,
  805.             componentRegion]
  806.  
  807.     
  808.     def _getBrailleRegionsForRadioButton(self, obj):
  809.         '''Get the braille for a radio button.  If the button already had
  810.         focus, then only the state is displayed.
  811.  
  812.         Arguments:
  813.         - obj: the check box
  814.  
  815.         Returns a list where the first element is a list of Regions to display
  816.         and the second element is the Region which should get focus.
  817.         '''
  818.         self._debugGenerator('_getBrailleRegionsForRadioButton', obj)
  819.         text = ''
  820.         state = obj.getState()
  821.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  822.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  823.         if not text and obj.description:
  824.             text = self._script.appendString(text, obj.description)
  825.         
  826.         text = self._script.appendString(text, self._getTextForRole(obj))
  827.         regions = []
  828.         if not state.contains(pyatspi.STATE_CHECKED):
  829.             pass
  830.         componentRegion = braille.Component(obj, text, indicator = settings.brailleRadioButtonIndicators[int(state.contains(pyatspi.STATE_PRESSED))])
  831.         regions.append(componentRegion)
  832.         return [
  833.             regions,
  834.             componentRegion]
  835.  
  836.     
  837.     def _getBrailleRegionsForRadioMenuItem(self, obj):
  838.         '''Get the braille for a radio menu item.  If the menu item
  839.         already had focus, then only the state is displayed.
  840.  
  841.         Arguments:
  842.         - obj: the check menu item
  843.  
  844.         Returns a list where the first element is a list of Regions to display
  845.         and the second element is the Region which should get focus.
  846.         '''
  847.         self._debugGenerator('_getBrailleRegionsForRadioMenuItem', obj)
  848.         text = ''
  849.         state = obj.getState()
  850.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  851.         text = self._script.appendString(text, self._script.getDisplayedText(obj))
  852.         if obj == orca_state.locusOfFocus:
  853.             text = self._script.appendString(text, self._getTextForRole(obj))
  854.             text = self._script.appendString(text, self._getTextForAvailability(obj))
  855.             text = self._script.appendString(text, self._getTextForAccelerator(obj), '')
  856.         
  857.         regions = []
  858.         componentRegion = braille.Component(obj, text, indicator = settings.brailleRadioButtonIndicators[int(state.contains(pyatspi.STATE_CHECKED))])
  859.         regions.append(componentRegion)
  860.         return [
  861.             regions,
  862.             componentRegion]
  863.  
  864.     
  865.     def _getBrailleRegionsForRowHeader(self, obj):
  866.         '''Get the braille for a row header.
  867.  
  868.         Arguments:
  869.         - obj: the column header
  870.  
  871.         Returns a list where the first element is a list of Regions to display
  872.         and the second element is the Region which should get focus.
  873.         '''
  874.         self._debugGenerator('_getBrailleRegionsForRowHeader', obj)
  875.         return self._getDefaultBrailleRegions(obj)
  876.  
  877.     
  878.     def _getBrailleRegionsForScrollBar(self, obj):
  879.         '''Get the braille for a scroll bar.
  880.  
  881.         Arguments:
  882.         - obj: the scroll bar
  883.  
  884.         Returns a list where the first element is a list of Regions to display
  885.         and the second element is the Region which should get focus.
  886.         '''
  887.         self._debugGenerator('_getBrailleRegionsForScrollBar', obj)
  888.         return self._getDefaultBrailleRegions(obj)
  889.  
  890.     
  891.     def _getBrailleRegionsForScrollPane(self, obj):
  892.         '''Get the braille for a scroll pane.
  893.  
  894.         Arguments:
  895.         - obj: the scroll pane
  896.  
  897.         Returns a list where the first element is a list of Regions to display
  898.         and the second element is the Region which should get focus.
  899.         '''
  900.         self._debugGenerator('_getBrailleRegionsForScrollPane', obj)
  901.         relations = obj.getRelationSet()
  902.         for relation in relations:
  903.             if relation.getRelationType() == pyatspi.RELATION_LABELLED_BY:
  904.                 labelledBy = relation.getTarget(0)
  905.                 return self._getBrailleRegionsForPageTab(labelledBy)
  906.         
  907.         return self._getDefaultBrailleRegions(obj)
  908.  
  909.     
  910.     def _getBrailleRegionsForSlider(self, obj):
  911.         '''Get the braille for a slider.  If the object already
  912.         had focus, just the value is displayed.
  913.  
  914.         Arguments:
  915.         - obj: the slider
  916.  
  917.         Returns a list where the first element is a list of Regions to display
  918.         and the second element is the Region which should get focus.
  919.         '''
  920.         self._debugGenerator('_getBrailleRegionsForSlider', obj)
  921.         regions = []
  922.         text = ''
  923.         text = self._script.appendString(text, self._script.getDisplayedLabel(obj))
  924.         text = self._script.appendString(text, self._script.getTextForValue(obj))
  925.         text = self._script.appendString(text, self._getTextForRole(obj))
  926.         text = self._script.appendString(text, self._getTextForRequiredObject(obj))
  927.         regions = []
  928.         componentRegion = braille.Component(obj, text)
  929.         regions.append(componentRegion)
  930.         return [
  931.             regions,
  932.             componentRegion]
  933.  
  934.     
  935.     def _getBrailleRegionsForSpinButton(self, obj):
  936.         '''Get the braille for a spin button.  If the object already has
  937.         focus, then only the new value is displayed.
  938.  
  939.         Arguments:
  940.         - obj: the spin button
  941.  
  942.         Returns a list where the first element is a list of Regions to display
  943.         and the second element is the Region which should get focus.
  944.         '''
  945.         self._debugGenerator('_getBrailleRegionsForSpinButton', obj)
  946.         return self._getBrailleRegionsForText(obj)
  947.  
  948.     
  949.     def _getBrailleRegionsForSplitPane(self, obj):
  950.         '''Get the braille for a split pane.
  951.  
  952.         Arguments:
  953.         - obj: the split pane
  954.  
  955.         Returns a list where the first element is a list of Regions to display
  956.         and the second element is the Region which should get focus.
  957.         '''
  958.         self._debugGenerator('_getBrailleRegionsForSplitPane', obj)
  959.         return self._getDefaultBrailleRegions(obj)
  960.  
  961.     
  962.     def _getBrailleRegionsForTable(self, obj):
  963.         '''Get the braille for a table
  964.  
  965.         Arguments:
  966.         - obj: the table
  967.  
  968.         Returns a list where the first element is a list of Regions to display
  969.         and the second element is the Region which should get focus.
  970.         '''
  971.         self._debugGenerator('_getBrailleRegionsForTable', obj)
  972.         return self._getDefaultBrailleRegions(obj)
  973.  
  974.     
  975.     def _getBrailleRegionsForTableCell(self, obj):
  976.         '''Get the braille for a single table cell
  977.  
  978.         Arguments:
  979.         - obj: the table
  980.  
  981.         Returns a list where the first element is a list of Regions to display
  982.         and the second element is the Region which should get focus.
  983.         '''
  984.         self._debugGenerator('_getBrailleRegionsForTableCell', obj)
  985.         regions = []
  986.         if obj.childCount == 2:
  987.             cellOrder = []
  988.             hasToggle = [
  989.                 False,
  990.                 False]
  991.             for i, child in enumerate(obj):
  992.                 
  993.                 try:
  994.                     action = child.queryAction()
  995.                 except:
  996.                     continue
  997.                     continue
  998.  
  999.                 for j in range(0, action.nActions):
  1000.                     if action.getName(j) in [
  1001.                         'toggle',
  1002.                         _('toggle')]:
  1003.                         hasToggle[i] = True
  1004.                         break
  1005.                         continue
  1006.                 
  1007.             
  1008.             if hasToggle[0] and not hasToggle[1]:
  1009.                 cellOrder = [
  1010.                     0,
  1011.                     1]
  1012.             elif not hasToggle[0] and hasToggle[1]:
  1013.                 cellOrder = [
  1014.                     1,
  1015.                     0]
  1016.             
  1017.             if cellOrder:
  1018.                 for i in cellOrder:
  1019.                     (cellRegions, focusRegion) = self._getBrailleRegionsForTableCell(obj[i])
  1020.                     if len(regions):
  1021.                         regions.append(braille.Region(' '))
  1022.                     else:
  1023.                         cellFocusedRegion = focusRegion
  1024.                     regions.append(cellRegions[0])
  1025.                 
  1026.                 regions = [
  1027.                     regions,
  1028.                     cellFocusedRegion]
  1029.                 return regions
  1030.         
  1031.         label = None
  1032.         
  1033.         try:
  1034.             action = obj.queryAction()
  1035.         except NotImplementedError:
  1036.             pass
  1037.  
  1038.         for i in range(0, action.nActions):
  1039.             debug.println(debug.LEVEL_FINEST, 'braillegenerator._getBrailleRegionsForTableCell ' + 'looking at action %d' % i)
  1040.             if action.getName(i) in [
  1041.                 'toggle',
  1042.                 _('toggle')]:
  1043.                 regions = self._getBrailleRegionsForCheckBox(obj)
  1044.                 label = self._script.getDisplayedText(self._script.getRealActiveDescendant(obj))
  1045.                 if label == None or len(label) == 0:
  1046.                     
  1047.                     try:
  1048.                         table = obj.parent.queryTable()
  1049.                         index = self._script.getCellIndex(obj)
  1050.                         n = table.getColumnAtIndex(index)
  1051.                         accHeader = table.getColumnHeader(n)
  1052.                         regions[0].append(braille.Region(' '))
  1053.                         label = accHeader.name
  1054.                         regions[0].append(braille.Region(label))
  1055.  
  1056.                 
  1057.                 break
  1058.                 continue
  1059.         
  1060.         descendant = self._script.getRealActiveDescendant(obj)
  1061.         if len(regions) == 0:
  1062.             regions = self._getDefaultBrailleRegions(descendant)
  1063.         else:
  1064.             cellText = self._script.getDisplayedText(descendant)
  1065.             if (not cellText or cellText) and label != cellText:
  1066.                 (cellRegions, focusRegion) = self._getDefaultBrailleRegions(descendant)
  1067.                 regions[0].extend(cellRegions)
  1068.             
  1069.         displayedText = self._script.getDisplayedText(self._script.getRealActiveDescendant(obj))
  1070.         
  1071.         try:
  1072.             image = obj.queryImage()
  1073.         except:
  1074.             image = None
  1075.  
  1076.         if (not displayedText or len(displayedText) == 0) and image:
  1077.             if image.imageDescription:
  1078.                 regions[0].append(braille.Component(obj, image.imageDescription))
  1079.             
  1080.             (cellRegions, focusRegion) = self._getBrailleRegionsForImage(obj)
  1081.             regions[0].extend(cellRegions)
  1082.         
  1083.         state = obj.getState()
  1084.         if state.contains(pyatspi.STATE_EXPANDABLE):
  1085.             if state.contains(pyatspi.STATE_EXPANDED):
  1086.                 regions[0].append(braille.Region(' ' + _('expanded')))
  1087.             else:
  1088.                 regions[0].append(braille.Region(' ' + _('collapsed')))
  1089.         
  1090.         return regions
  1091.  
  1092.     
  1093.     def _getBrailleRegionsForTableCellRow(self, obj):
  1094.         '''Get the braille for a table cell row or a single table cell
  1095.         if settings.readTableCellRow is False.
  1096.  
  1097.         Arguments:
  1098.         - obj: the table
  1099.  
  1100.         Returns a list where the first element is a list of Regions to display
  1101.         and the second element is the Region which should get focus.
  1102.         '''
  1103.         self._debugGenerator('_getBrailleRegionsForTableColumnHeader', obj)
  1104.         regions = []
  1105.         
  1106.         try:
  1107.             table = obj.parent.queryTable()
  1108.         except NotImplementedError:
  1109.             table = None
  1110.  
  1111.         if settings.readTableCellRow and table and not self._script.isLayoutOnly(obj.parent):
  1112.             rowRegions = []
  1113.             savedBrailleVerbosityLevel = settings.brailleVerbosityLevel
  1114.             settings.brailleVerbosityLevel = settings.VERBOSITY_LEVEL_BRIEF
  1115.             index = self._script.getCellIndex(obj)
  1116.             row = table.getRowAtIndex(index)
  1117.             column = table.getColumnAtIndex(index)
  1118.             speakAll = True
  1119.             if 'lastRow' in self._script.pointOfReference and 'lastColumn' in self._script.pointOfReference:
  1120.                 pointOfReference = self._script.pointOfReference
  1121.                 if not pointOfReference['lastRow'] != row:
  1122.                     if row == 0 or row == table.nRows - 1:
  1123.                         pass
  1124.                 speakAll = pointOfReference['lastColumn'] == column
  1125.             
  1126.             if speakAll:
  1127.                 focusRowRegion = None
  1128.                 for i in range(0, table.nColumns):
  1129.                     cell = table.getAccessibleAt(row, i)
  1130.                     if not cell:
  1131.                         debug.println(debug.LEVEL_WARNING, 'ERROR: braillegenerator.' + '_getBrailleRegionsForTableCellRow' + ' no accessible at (%d, %d)' % (row, i))
  1132.                         continue
  1133.                     
  1134.                     state = cell.getState()
  1135.                     showing = state.contains(pyatspi.STATE_SHOWING)
  1136.                     if showing:
  1137.                         (cellRegions, focusRegion) = self._getBrailleRegionsForTableCell(cell)
  1138.                         if len(rowRegions):
  1139.                             rowRegions.append(braille.Region(' '))
  1140.                         
  1141.                         rowRegions.extend(cellRegions)
  1142.                         if i == column:
  1143.                             focusRowRegion = cellRegions[0]
  1144.                         
  1145.                     i == column
  1146.                 
  1147.                 regions = [
  1148.                     rowRegions,
  1149.                     focusRowRegion]
  1150.             else:
  1151.                 regions = self._getBrailleRegionsForTableCell(obj)
  1152.             settings.brailleVerbosityLevel = savedBrailleVerbosityLevel
  1153.         else:
  1154.             regions = self._getBrailleRegionsForTableCell(obj)
  1155.         level = self._script.getNodeLevel(obj)
  1156.         if level >= 0:
  1157.             regions[0].append(braille.Region(' ' + _('TREE LEVEL %d') % (level + 1)))
  1158.         
  1159.         return regions
  1160.  
  1161.     
  1162.     def _getBrailleRegionsForTableColumnHeader(self, obj):
  1163.         '''Get the braille for a table column header
  1164.  
  1165.         Arguments:
  1166.         - obj: the table column header
  1167.  
  1168.         Returns a list where the first element is a list of Regions to display
  1169.         and the second element is the Region which should get focus.
  1170.         '''
  1171.         self._debugGenerator('_getBrailleRegionsForTableColumnHeader', obj)
  1172.         return self._getBrailleRegionsForColumnHeader(obj)
  1173.  
  1174.     
  1175.     def _getBrailleRegionsForTableRowHeader(self, obj):
  1176.         '''Get the braille for a table row header
  1177.  
  1178.         Arguments:
  1179.         - obj: the table row header
  1180.  
  1181.         Returns a list where the first element is a list of Regions to display
  1182.         and the second element is the Region which should get focus.
  1183.         '''
  1184.         self._debugGenerator('_getBrailleRegionsForTableRowHeader', obj)
  1185.         return self._getBrailleRegionsForRowHeader(obj)
  1186.  
  1187.     
  1188.     def _getBrailleRegionsForTearOffMenuItem(self, obj):
  1189.         '''Get the braille for a tear off menu item
  1190.  
  1191.         Arguments:
  1192.         - obj: the tear off menu item
  1193.  
  1194.         Returns a list where the first element is a list of Regions to display
  1195.         and the second element is the Region which should get focus.
  1196.         '''
  1197.         self._debugGenerator('_getBrailleRegionsForTearOffMenuItem', obj)
  1198.         componentRegion = braille.Component(obj, rolenames.getBrailleForRoleName(obj))
  1199.         return [
  1200.             [
  1201.                 componentRegion],
  1202.             componentRegion]
  1203.  
  1204.     
  1205.     def _getBrailleRegionsForTerminal(self, obj):
  1206.         '''Get the braille for a terminal
  1207.  
  1208.         Arguments:
  1209.         - obj: the terminal
  1210.  
  1211.         Returns a list where the first element is a list of Regions to display
  1212.         and the second element is the Region which should get focus.
  1213.         '''
  1214.         self._debugGenerator('_getBrailleRegionsForTerminal', obj)
  1215.         regions = []
  1216.         textRegion = braille.Text(obj)
  1217.         regions.append(textRegion)
  1218.         return [
  1219.             regions,
  1220.             textRegion]
  1221.  
  1222.     
  1223.     def _getBrailleRegionsForToggleButton(self, obj):
  1224.         '''Get the braille for a toggle button.  If the toggle button already
  1225.         had focus, then only the state is displayed.
  1226.  
  1227.         Arguments:
  1228.         - obj: the check box
  1229.  
  1230.         Returns a list where the first element is a list of Regions to display
  1231.         and the second element is the Region which should get focus.
  1232.         '''
  1233.         self._debugGenerator('_getBrailleRegionsForToggleButton', obj)
  1234.         return self._getBrailleRegionsForRadioButton(obj)
  1235.  
  1236.     
  1237.     def _getBrailleRegionsForToolBar(self, obj):
  1238.         '''Get the braille for a tool bar
  1239.  
  1240.         Arguments:
  1241.         - obj: the tool bar
  1242.  
  1243.         Returns a list where the first element is a list of Regions to display
  1244.         and the second element is the Region which should get focus.
  1245.         '''
  1246.         self._debugGenerator('_getBrailleRegionsForToolBar', obj)
  1247.         return self._getDefaultBrailleRegions(obj)
  1248.  
  1249.     
  1250.     def _getBrailleRegionsForTree(self, obj):
  1251.         '''Get the braille for a tree
  1252.  
  1253.         Arguments:
  1254.         - obj: the tree
  1255.  
  1256.         Returns a list where the first element is a list of Regions to display
  1257.         and the second element is the Region which should get focus.
  1258.         '''
  1259.         self._debugGenerator('_getBrailleRegionsForTreeTable', obj)
  1260.         return self._getDefaultBrailleRegions(obj)
  1261.  
  1262.     
  1263.     def _getBrailleRegionsForTreeTable(self, obj):
  1264.         '''Get the braille for a tree table
  1265.  
  1266.         Arguments:
  1267.         - obj: the tree table
  1268.  
  1269.         Returns a list where the first element is a list of Regions to display
  1270.         and the second element is the Region which should get focus.
  1271.         '''
  1272.         self._debugGenerator('_getBrailleRegionsForTreeTable', obj)
  1273.         return self._getDefaultBrailleRegions(obj)
  1274.  
  1275.     
  1276.     def _getBrailleRegionsForWindow(self, obj):
  1277.         '''Get the braille for a window
  1278.  
  1279.         Arguments:
  1280.         - obj: the window
  1281.  
  1282.         Returns a list where the first element is a list of Regions to display
  1283.         and the second element is the Region which should get focus.
  1284.         '''
  1285.         self._debugGenerator('_getBrailleRegionsForWindow', obj)
  1286.         return self._getDefaultBrailleRegions(obj)
  1287.  
  1288.     
  1289.     def getBrailleRegions(self, obj, groupChildren = True):
  1290.         '''Get the braille regions for an Accessible object.  This
  1291.         will look first to the specific braille generators and then to
  1292.         the default braille generator.  This method is the primary
  1293.         method that external callers of this class should use.
  1294.  
  1295.         Arguments:
  1296.         - obj: the object
  1297.         - groupChildren: if True, children of an object should be displayed
  1298.                          together with their parent, where each child is
  1299.                          separated by _ and the selected child is the Region
  1300.                          that should get focus.  The default here is True,
  1301.                          but this also is used in conjunction with
  1302.                          settings.enableBrailleGrouping.
  1303.  
  1304.         Returns a list where the first element is a list of Regions to
  1305.         display and the second element is the Region which should get
  1306.         focus.
  1307.         '''
  1308.         reallyGroupChildren = False
  1309.         if settings.enableBrailleGrouping and groupChildren:
  1310.             parent = obj.parent
  1311.             if not parent and parent.getRole() == pyatspi.ROLE_MENU and parent.getRole() == pyatspi.ROLE_MENU_BAR:
  1312.                 pass
  1313.             isChild = parent.getRole() == pyatspi.ROLE_PAGE_TAB_LIST
  1314.             if isChild:
  1315.                 obj = parent
  1316.                 reallyGroupChildren = True
  1317.             elif not obj.getRole() == pyatspi.ROLE_MENU and obj.getRole() == pyatspi.ROLE_MENU_BAR:
  1318.                 pass
  1319.             reallyGroupChildren = obj.getRole() == pyatspi.ROLE_PAGE_TAB_LIST
  1320.         
  1321.         role = obj.getRole()
  1322.         if role in self.brailleGenerators:
  1323.             generator = self.brailleGenerators[role]
  1324.         else:
  1325.             generator = self._getDefaultBrailleRegions
  1326.         result = generator(obj)
  1327.         regions = result[0]
  1328.         selectedRegion = result[1]
  1329.         if reallyGroupChildren:
  1330.             regions.append(braille.Region(' '))
  1331.             
  1332.             try:
  1333.                 selection = obj.querySelection()
  1334.             except NotImplementedError:
  1335.                 selection = None
  1336.  
  1337.             i = 0
  1338.             for child in obj:
  1339.                 debug.println(debug.LEVEL_FINEST, 'braillegenerator.getBrailleRegions ' + 'looking at child %d' % i)
  1340.                 if child and child.getRole() != pyatspi.ROLE_SEPARATOR:
  1341.                     if i > 0 and i < (self, obj.childCount - 1):
  1342.                         regions.append(braille.Region(' _ '))
  1343.                     
  1344.                     result = self.getBrailleRegions(child, False)
  1345.                     regions.extend(result[0])
  1346.                     if selection or selection.isChildSelected(i) or child.getState().contains(pyatspi.STATE_ARMED):
  1347.                         selectedRegion = result[1]
  1348.                     
  1349.                 
  1350.                 i += 1
  1351.             
  1352.         
  1353.         return [
  1354.             regions,
  1355.             selectedRegion]
  1356.  
  1357.     
  1358.     def getBrailleContext(self, obj):
  1359.         '''Get the braille regions that describe the context (i.e.,
  1360.         names/roles of the container hierarchy) of the object.
  1361.  
  1362.         Arguments:
  1363.         - obj: the object
  1364.  
  1365.         Returns a list of Regions to display.
  1366.         '''
  1367.         brailleRolenameStyle = settings.brailleRolenameStyle
  1368.         regions = []
  1369.         if not settings.enableBrailleContext:
  1370.             return regions
  1371.         parent = obj.parent
  1372.         if parent and parent.getRole() in self.SKIP_CONTEXT_ROLES:
  1373.             parent = parent.parent
  1374.         
  1375.         while parent and parent.parent != parent:
  1376.             if parent.getRole() != pyatspi.ROLE_FILLER and parent.getRole() != pyatspi.ROLE_SECTION and parent.getRole() != pyatspi.ROLE_SPLIT_PANE and not self._script.isLayoutOnly(parent):
  1377.                 label = self._script.getDisplayedLabel(parent)
  1378.                 text = self._script.getDisplayedText(parent)
  1379.                 regions.append(braille.Region(' '))
  1380.                 result = self.getBrailleRegions(parent, False)
  1381.                 regions.extend(result[0])
  1382.             
  1383.             if parent.getRole() == pyatspi.ROLE_FILLER:
  1384.                 label = self._script.getDisplayedLabel(parent)
  1385.                 if label and len(label) and not label.isspace():
  1386.                     regions.append(braille.Region(' '))
  1387.                     result = self.getBrailleRegions(parent, False)
  1388.                     regions.extend(result[0])
  1389.                 
  1390.             
  1391.             parent = parent.parent
  1392.         regions.reverse()
  1393.         parent = obj.parent
  1394.         
  1395.         try:
  1396.             table = parent.queryTable()
  1397.         except (NotImplementedError, AttributeError):
  1398.             table = None
  1399.  
  1400.         if parent and table:
  1401.             index = self._script.getCellIndex(obj)
  1402.             row = table.getRowAtIndex(index)
  1403.             if row >= 0 and obj.getRole() not in [
  1404.                 pyatspi.ROLE_ROW_HEADER,
  1405.                 pyatspi.ROLE_TABLE_ROW_HEADER]:
  1406.                 desc = table.getRowDescription(row)
  1407.                 if not desc:
  1408.                     header = table.getRowHeader(row)
  1409.                     if header:
  1410.                         desc = self._script.getDisplayedText(header)
  1411.                     
  1412.                 
  1413.             else:
  1414.                 desc = None
  1415.             if desc and len(desc):
  1416.                 if settings.brailleRolenameStyle == settings.VERBOSITY_LEVEL_VERBOSE:
  1417.                     if brailleRolenameStyle == settings.BRAILLE_ROLENAME_STYLE_LONG:
  1418.                         text = desc + ' ' + rolenames.rolenames[pyatspi.ROLE_ROW_HEADER].brailleLong + ' '
  1419.                     else:
  1420.                         text = desc + ' ' + rolenames.rolenames[pyatspi.ROLE_ROW_HEADER].brailleShort + ' '
  1421.                 else:
  1422.                     text = desc
  1423.                 regions.append(braille.Region(text))
  1424.             
  1425.             col = table.getColumnAtIndex(index)
  1426.             if col >= 0 and obj.getRole() not in [
  1427.                 pyatspi.ROLE_COLUMN_HEADER,
  1428.                 pyatspi.ROLE_TABLE_COLUMN_HEADER]:
  1429.                 desc = table.getColumnDescription(col)
  1430.                 if not desc:
  1431.                     header = table.getColumnHeader(col)
  1432.                     if header:
  1433.                         desc = self._script.getDisplayedText(header)
  1434.                     
  1435.                 
  1436.             else:
  1437.                 desc = None
  1438.             if desc and len(desc):
  1439.                 if settings.brailleVerbosityLevel == settings.VERBOSITY_LEVEL_VERBOSE:
  1440.                     if brailleRolenameStyle == settings.BRAILLE_ROLENAME_STYLE_LONG:
  1441.                         text = desc + ' ' + rolenames.rolenames[pyatspi.ROLE_COLUMN_HEADER].brailleLong + ' '
  1442.                     else:
  1443.                         text = desc + ' ' + rolenames.rolenames[pyatspi.ROLE_COLUMN_HEADER].brailleShort + ' '
  1444.                 else:
  1445.                     text = desc
  1446.                 regions.append(braille.Region(text))
  1447.             
  1448.         
  1449.         return regions
  1450.  
  1451.  
  1452.